package com.zhongxing.administrator.spritelhd;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {
    private Button btn_login;
    private Button btn_logout;
    private EditText et_account;
    private EditText et_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initUI();

    }

    /**
     * 初始化控件
     */
    private void initUI(){


        et_account= (EditText) findViewById(R.id.et_account);
        et_password= (EditText) findViewById(R.id.et_password);
        btn_login =(Button) findViewById(R.id.btn_login);
        btn_logout=(Button) findViewById(R.id.btn_logout);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                checkEidtText();


            }
        });

    }
    private void checkEidtText(){
        if (et_account.getText().toString().isEmpty()){
            Toast.makeText(getApplicationContext(),"账号不能为空",Toast.LENGTH_SHORT).show();
        }
        else if(et_password.getText().toString().isEmpty()){

            Toast.makeText(getApplicationContext(),"密码不能为空",Toast.LENGTH_SHORT).show();

        }else if(et_account.length()<5){

            Toast.makeText(getApplicationContext(),"账号不能小于五位",Toast.LENGTH_SHORT).show();

        }else if(et_password.length()<3){

            Toast.makeText(getApplicationContext(),"密码不能小于三位",Toast.LENGTH_SHORT).show();

        }else if (et_account.getText().toString().equals("admin")&&et_password.getText().toString().equals("123")){


            Toast.makeText(getApplicationContext(),"登陆成功",Toast.LENGTH_SHORT).show();
            Intent intent =new Intent(getApplicationContext(),MainActivity.class);
            startActivity(intent);
        }else {
            Toast.makeText(getApplicationContext(),"密码或账号错误",Toast.LENGTH_SHORT).show();
        }





    }
}
